<?php
/**
* 我的评价
*/
class Reviews extends CS_Controller
{
    public function _init()
    {
        $this->load->model('scenery_reviews_model', 'scenery_reviews');
        $this->load->model('line_product_reviews_model', 'line_product_reviews');
        $this->load->model('tourism_order_reviews_model', 'tourism_order_reviews');
    }

    public function index()
    {
        $this->load->view('home/reviews/index', $this->data);
    }

    /**
     * 景区评价列表
     */
    public function sceneryReview()
    {
        $page = 20;
        $params = array('uid' => $this->uid, 'status' => 2);
        $total = $this->scenery_reviews->reviewTotal($params);
        if ($total > 0) {
            $this->data['reviewsList'] = $this->scenery_reviews->queryReview($params, 0, $page);
        }
        $this->data['more'] = $total > $page ? true : false;
        $this->load->view('home/reviews/sceneryReview', $this->data);
    }

    /**
     * ajax查询景区评价
     */
    public function ajaxSceneryReview()
    {
        $page = $this->input->post('page');
        $num = 20;
        $params = array('uid' => $this->uid, 'status' => 2);
        $total = $this->scenery_reviews->reviewTotal($params);
        $data['reviewsList'] = $this->scenery_reviews->queryReview($params, $num * $page, $num);
        echo json_encode(
                array(
                    'status' => ($total >  ($page + 1) * $num) ? true : false,
                    'html'   => $this->load->view('home/reviews/ajaxSceneryReview', $data, true)
                )
            );
        exit;
    }

    /**
     * 酒店评价
     */
    public function hotelReview()
    {
        $this->load->view('home/reviews/hotelReview', $this->data);
    }

    /**
     * 线路评价
     */
    public function lineReview()
    {
        $page = 20;
        $params = array('uid' => $this->uid, 'status' => 2);
        $total = $this->line_product_reviews->reviewTotal($params);
        if ($total > 0) {
            $this->data['reviewsList'] = $this->line_product_reviews->queryReview($params, 0, $page);
        }
        $this->data['more'] = $total > $page ? true : false;
        $this->load->view('home/reviews/lineReview', $this->data);
    }

    /**
     * ajax查询线路评价
     */
    public function ajaxLineReview()
    {
        $page = $this->input->post('page');
        $num = 20;
        $params = array('uid' => $this->uid, 'status' => 2);
        $total = $this->line_product_reviews->reviewTotal(array('uid' => $this->uid));
        $data['reviewsList'] = $this->line_product_reviews->queryReview(array('uid' => $this->uid), $num * $page, $num);
        echo json_encode(
                array(
                    'status' => ($total >  ($page + 1) * $num) ? true : false,
                    'html'   => $this->load->view('home/reviews/ajaxLineReview', $data, true)
                )
            );
        exit;
    }

    /**
     * 商品评价
     */
    public function tourismReview()
    {
        $page = 20;
        $params = array('uid' => $this->uid, 'status' => 2);
        $total = $this->tourism_order_reviews->reviewTotal($params);
        if ($total > 0) {
            $this->data['reviewsList'] = $this->tourism_order_reviews->queryReview($params, 0, $page);
        }
        $this->data['more'] = $total > $page ? true : false;
        $this->load->view('home/reviews/tourismReview', $this->data);
    }

    /**
     * ajax查询商品评价
     */
    public function ajaxTourismReview()
    {
        $page = $this->input->post('page');
        $num = 20;
        $params = array('uid' => $this->uid, 'status' => 2);
        $total = $this->tourism_order_reviews->reviewTotal($params);
        $data['reviewsList'] = $this->tourism_order_reviews->queryReview($params, $num * $page, $num);
        echo json_encode(
                array(
                    'status' => ($total >  ($page + 1) * $num) ? true : false,
                    'html'   => $this->load->view('home/reviews/ajaxTourismReview', $data, true)
                )
            );
        exit;
    }
}